<?php

namespace App\Http\Controllers\School;

use App\Http\Requests\School\EditSchool;
use App\Http\Resources\School\SchoolResource;
use App\Models\School;
use App\Models\SchoolAdminLog;
use App\Services\SchoolService;

/**
 * Class SchoolController
 * @package App\Http\Controllers\School
 * 学校后台学校管理
 */
class SchoolController extends BaseController
{
    /**
     * @return SchoolResource
     * 展示学校信息
     */
    public function index()
    {
        $school = School::findOrFail(\Auth::user()->school_id);
        return new SchoolResource($school);
    }

    /**
     * @param EditSchool $request
     * @param School $school
     * @return SchoolResource
     * 编辑学校信息
     */
    public function update(EditSchool $request, School $school)
    {
        $school = SchoolService::edit($school);
        SchoolAdminLog::Log('修改学校信息');
        return new SchoolResource($school);
    }
}
